博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
基于ARM的智能灯光控制系统(8)设备添加
阅读量:7015 次
发布时间:2019-06-28

本文共 5943 字,大约阅读时间需要 19 分钟。

基于ARM的智能灯光控制系统(8)设备添加

设备添加页面

这里写图片描述

网页显示头文件(html.h)

#include 
#define ERR_SHM 1#define ERR_MSG 2#define ERR_REG 3void html_head(){ printf("Content-type:text/html\r\n\r\n"); printf(""); printf("
SL1200智能灯光控制系统"); printf("
"); printf("
"); printf("
");}void html_refresh(char* second, char* url){ printf("
",second, url);}void html_title(){ printf("
"); ...}void html_nav(){ printf("
"); ... }void html_table_title(char* title,char * title1,char *title2){ ...}void html_table_head(int len, char argv[][10],char* title){ ...}void html_table_end(){ printf("
");}void html_end(){ ... printf("");}void html_return_info(char* info){ printf("
"); printf("
"); printf("设置结果
"); printf("
%s", info); printf("
");}void html_return_show(int ret){ if(ret == 0){ html_return_info("设置完成,返回界面."); }else{ switch(ret){ case ERR_SHM: html_return_info("共享内存错误."); break; case ERR_MSG: html_return_info("区域记录己满."); break; case ERR_REG: html_return_info("区域记录己满."); break; default: html_return_info("设置失败,未知错误."); break; } }}

进程通信头文件(ipc.h)

#ifndef __IPC_H_#define __IPC_H_#include 
#include
#include
#include
#include
#define CMD_GET 1#define CMD_SET 2int get_msgid(void){ int id = -1; id = msgget((key_t)1234,0666|IPC_CREAT); return id;}void* set_web_shm(void){ int shmid; void* shmaddr=(void*)0; if((shmid=shmget((key_t)1122,sizeof(struct sys_all),0666|IPC_CREAT))<0){ return NULL; }else{ if((shmaddr=shmat(shmid,(void*)0,0))==(char *)-1){ return NULL; } } return shmaddr;}int msg_send(int msgid,int cmd_da){ struct st_msg_req cmd; cmd.index = WEB_UPDATE_SMG_INDEX; cmd.req = cmd_da; if(msgsnd(msgid,(void*)&cmd,1,0)==-1) return -1; return 0;}#endif

设备添加页面程序(dev_add.c)

#include 
#include
#include
#include
#include "html.h"#include "config.h"#include "ipc.h"void table_tr(char* name,char type,int checked){ char type_id[2]="0"; type_id[0] = type + '0'; printf("
",type_id,name); //显示id printf("
",type_id,type_id); switch(type) { case 1: printf("主控制器"); break; case 2: printf("分控制器"); break; case 3: printf("光线感应"); break; case 4: printf("人体感应"); break; case 5: printf("声音感应"); break; case 6: case 7: printf("灯光设备"); break; case 8: printf("网络设备"); break; default: break; } if(checked==1) { printf("
连通
断开",type_id,type_id); }else{ printf("
连通
断开",type_id,type_id); } printf("
");}int main(int argc, char *argv[]){ int ret = 0; int i,msgid; struct sys_all* shm_dev; char item_name[5][10]; if((msgid=get_msgid()) < 0){ ret = ERR_MSG; } if(msg_send(msgid,CMD_GET)==0){ if((shm_dev=(struct sys_all*)set_web_shm())==NULL){ ret = ERR_SHM; } } html_head(); html_title(); html_nav(); html_table_title("设备添加" , "设备设置" , "设备添加" ); if(ret != 0){ html_return_show(ret); html_end(); return 0; } printf("
"); strcpy(item_name[0],"设备名称"); strcpy(item_name[1],"节点信息"); strcpy(item_name[2],"设备类型"); strcpy(item_name[3],"连接状态"); strcpy(item_name[4],"提交操作"); html_table_head(5,item_name,"设备列表"); for(i=0;i
count_dev;i++){ table_tr(shm_dev->sys_dev[i].name,shm_dev->sys_dev[i].node.type, shm_dev->sys_dev[i].join_sta); } html_table_end(); printf(""); html_end(); return 0;}

页面处理程序(dev_add_post.c)

#include 
#include
#include
#include
#include "getvalue.h"#include "html.h"#include "config.h"#include "ipc.h"int main(int argc, char *argv[]){ int ret = 0; char *val = NULL; char val_name[16]; char type_id[2]="0"; int i,msgid; struct sys_all* shm_dev; set_env(getenv("REQUEST_METHOD"), getenv("CONTENT_LENGTH"), getenv("QUERY_STRING")); html_head(); html_refresh("3","/cgi-bin/dev_add.cgi"); html_title(); html_nav(); html_table_title("设备添加" , "设备设置" , "设备添加" ); if((shm_dev=(struct sys_all*)set_web_shm())==NULL){ ret = ERR_SHM; }else{ for(i=0;i
count_dev;i++){ //根据配置文件实时数据,动态读取变量名join_sta+id type_id[0] = shm_dev->sys_dev[i].node.type + '0'; strcpy(val_name,"join_sta"); strcat(val_name,type_id); val = get_value(val_name); shm_dev->sys_dev[i].join_sta = val[0]-'0'; strcpy(val_name,"name_"); strcat(val_name,type_id); val = get_value(val_name); strcpy(shm_dev->sys_dev[i].name,val); } } if(ret == 0){ if((msgid=get_msgid()) < 0){ ret = ERR_MSG; } if(msg_send(msgid,CMD_SET) < 0) ret = ERR_MSG; } html_return_show(ret); html_end(); return 0;}

转载于:https://blog.51cto.com/91arm/2052758

你可能感兴趣的文章
HTML导航栏的四种制作方法,jQuery+CSS3实现四种应用广泛的导航条制作实例详解
查看>>
html nobr 无效,HTML
查看>>
浏览器怎么解析css和html,浏览器解析html css js
查看>>
Microsoft Azure部署MYSQL-MMM(1)安装MYSQL
查看>>
Puppet根据节点机器名推送并自动执行SHELL脚本
查看>>
Hyper-v虚拟化平台VDI 部署参考v1.0版
查看>>
话里话外:企业管理软件的方案设计要规避哪些风险
查看>>
晒一晒老司机写的“超融合私有云”解决方案
查看>>
灵活强大的MySQL代理中间件ProxySQL应用实战(2)
查看>>
免费下载 《敏捷个人-认识自我,管理自我 v0.8.pdf》
查看>>
使用AspNetPager控件分页
查看>>
大神,快来救救我,我搞不定啊
查看>>
Kafka 入门 and kafka+logstash 实战应用
查看>>
Apache+varnish(高性能开源HTTP加速器)搭建负载均衡集群
查看>>
FTP文件传输服务
查看>>
windows 7 驱动安装时间过长 无响应的解决办法
查看>>
Docker storage driver(十四)
查看>>
RHCE 学习笔记(14)- 文件系统 (1)
查看>>
[jQuery] 基础知识
查看>>
JQuery获取DOM元素
查看>>